import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jinke/utils/gallery/gallery.dart';
import 'package:jinke/utils/gallery/model.dart';
import 'package:photo_browser/photo_browser.dart';

import '../../../../../../utils/util.dart';
import '../../model/pro_detail_model/pro_detail_model.dart';
import 'index.dart';

class ProProgressDayPage extends StatelessWidget {
  ProProgressDayPage({
    Key? key,
    this.mod,
  }) {
    controller.state.mod = mod;
    controller.getList();
  }
  final ProDetailModel? mod;
  final controller = Get.put(ProProgressDayController());
  // 主视图
  Widget _buildView() {
    var state = controller.state;
    return ListView.builder(
      padding: EdgeInsets.all(16.r),
      physics: const NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      itemCount: state.showList.length,
      itemBuilder: (context, index) {
        var md = state.showList[index];
        return BrnStepLine(
          lineWidth: 1,
          //非第一个是灰色
          isGrey: index != 0,
          //最后一个的线条为透明色 做到不显示的效果
          lineColor: const Color(0xffeeeeee),
          contentWidget: Container(
            padding: const EdgeInsets.only(left: 8),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Visibility(
                  visible: !isNilStr(md.date),
                  child: Container(
                    margin: EdgeInsets.only(bottom: 20.r),
                    child: Text(
                      md.date ?? '',
                      style: TextStyle(
                        height: 0.9,
                        color: BrnThemeConfigurator.instance
                            .getConfig()
                            .commonConfig
                            .colorTextBase,
                        fontSize: 16,
                      ),
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.only(bottom: 20),
                  child: Text(
                    md.time ?? '',
                    style: TextStyle(
                      color: BrnThemeConfigurator.instance
                          .getConfig()
                          .commonConfig
                          .colorTextSecondary,
                      fontSize: 14,
                    ),
                  ),
                ),
                Container(
                    padding:
                        EdgeInsets.symmetric(horizontal: 16.r, vertical: 18.r),
                    margin: EdgeInsets.only(bottom: 15.r),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(4.r)),
                    child: Column(
                      children: [
                        Text.rich(
                          TextSpan(children: [
                            WidgetSpan(
                              child: Container(
                                decoration: BoxDecoration(
                                  color: md.date != null
                                      ? const Color(0xffEF7F13).withAlpha(30)
                                      : const Color(0xffF2F3F7),
                                  borderRadius: BorderRadius.circular(2.r),
                                ),
                                margin: EdgeInsets.only(right: 5.r),
                                padding: EdgeInsets.symmetric(
                                    horizontal: 5.r, vertical: 2.r),
                                child: Text(
                                  md.name ?? '',
                                  style: TextStyle(
                                      color: md.date != null
                                          ? const Color(0xffEF7F13)
                                          : ColorsUtil.blue,
                                      fontSize: 10.sp),
                                ),
                              ),
                            ),
                            TextSpan(
                                text: md.content,
                                style: TextStyle(
                                  color: ColorsUtil.title,
                                  fontSize: 14.sp,
                                ))
                          ]),
                        ),
                        SizedBox(
                          height: 10.r,
                        ),
                        Wrap(
                          // direction: Axis.vertical,
                          runSpacing: 10.r,
                          spacing: 10.r,
                          children: md.files
                                  ?.asMap()
                                  .map(
                                    (key, value) => MapEntry(
                                      key,
                                      Hero(
                                        tag: value.id ?? '',
                                        child: InkWell(
                                          onTap: () {
                                            PhotoBrowser photoBrowser =
                                                PhotoBrowser(
                                                    itemCount: md.files!.length,
                                                    initIndex: key,
                                                    controller:
                                                        PhotoBrowerController(),
                                                    allowTapToPopBuilder:
                                                        (int index) {
                                                      if (index == 7) {
                                                        return false;
                                                      }
                                                      return true;
                                                    },
                                                    allowSwipeDownToPop: true,
                                                    // If allowPullDownToPop is true, the allowSwipeDownToPop setting is invalid.
                                                    // 如果allowPullDownToPop为true，则allowSwipeDownToPop设置无效
                                                    allowPullDownToPop: true,
                                                    heroTagBuilder:
                                                        (int index) {
                                                      return value.id ?? '';
                                                    },
                                                    displayTypeBuilder:
                                                        (int index) {
                                                      return DisplayType.image;
                                                    },
                                                    imageUrlBuilder:
                                                        (int urlBuilderindex) {
                                                      return value.sourcePath ??
                                                          '';
                                                    },
                                                    // Thumbnails setting.
                                                    // 缩略图设置
                                                    thumImageUrlBuilder:
                                                        (int thumUrlindex) {
                                                      return value
                                                              .thumbnailPath ??
                                                          '';
                                                    });

                                            photoBrowser.push(context);
                                          },
                                          child: Container(
                                            width: 120.r,
                                            height: 150.r,
                                            child: Image.network(
                                                value.thumbnailPath ?? '',
                                                fit: BoxFit.cover),
                                          ),
                                        ),
                                      ),
                                    ),
                                  )
                                  .values
                                  .toList() ??
                              [],
                        )
                      ],
                    ))
              ],
            ),
          ),
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProProgressDayController>(
      id: "pro_progress_day",
      builder: (_) {
        return Scaffold(
          body: SafeArea(
            child: _buildView(),
          ),
          floatingActionButtonLocation:
              FloatingActionButtonLocation.centerDocked,
          floatingActionButton: Container(
            margin: EdgeInsets.only(bottom: 80.r),
            alignment: Alignment.bottomRight,
            child: InkWell(
              onTap: () {
                Get.toNamed(RouterPath.editAttractPage)!.then((value) {
                  if (value) {
                    controller.getList();
                  }
                });
              },
              child: Container(
                width: 93.r,
                height: 40.r,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  gradient: const LinearGradient(
                    colors: [
                      Color(0xff00A9FE),
                      Color(0xff0173FE),
                    ],
                    begin: Alignment.centerLeft,
                    end: Alignment.centerRight,
                  ),
                  borderRadius: BorderRadius.horizontal(
                    left: Radius.circular(20.r),
                  ),
                ),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Icon(
                      Icons.add,
                      color: Colors.white,
                      size: 20.r,
                    ),
                    Text(
                      '填进展',
                      style: TextStyle(color: Colors.white, fontSize: 15.r),
                    )
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
  }
}
